package com.yanq.liancar.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanq.liancar.R;
import com.yanq.liancar.bean.FindMsgBean;
import com.yanq.liancar.util.Constant;
import com.yanq.liancar.view.recyclerview.RecyclerAdapter;
import com.yanq.liancar.view.recyclerview.RecyclerHolder;
import com.yanq.liancar.view.recyclerview.RecyclerListener;

import java.util.List;

public class FindMsgAdapter extends RecyclerAdapter<FindMsgBean.DataBean.ListBean> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    public FindMsgAdapter(Context context, List<FindMsgBean.DataBean.ListBean> data) {
        super(context, data, R.layout.item_find_msg);
    }

    @Override
    public void convert(RecyclerHolder holder, FindMsgBean.DataBean.ListBean model) {
        ImageView findMsgIcon = holder.findViewById(R.id.find_msg_icon);
        TextView findMsgNick = holder.findViewById(R.id.find_msg_nick);
        StringBuilder sb = new StringBuilder();
        String nick = model.getUsername();
        sb.append(nick).append(" ");
        switch (mType) {
            case Constant.FIND_COMM:
                findMsgIcon.setImageResource(R.mipmap.plun);
                sb.append("评论了您: ").append(model.getComments());
                break;
            case Constant.FIND_LIKE:
                sb.append("赞了您");
                findMsgIcon.setImageResource(R.mipmap.zan);
                break;
        }
        SpannableString spannable = new SpannableString(sb.toString());
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#39567F"));
        spannable.setSpan(colorSpan, 0, nick.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        findMsgNick.setText(spannable);

//        TextView findMsgTitle = holder.findViewById(R.id.find_msg_title);
//        RecyclerView findMsgImage = holder.findViewById(R.id.find_msg_image);

        holder.setTvText(R.id.find_msg_time, model.getCommentTime());
        holder.setTvText(R.id.find_msg_content, model.getCommentContent());

        holder.setOnClickListener(this, R.id.find_msg_root);
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {

    }
}